package com.example.farmeri.adapter;
import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * Create by weiqishan on 2020/4/6.
 * 为每个Recycle中的字View设置间隔
 */
public class MyItemDecoration extends RecyclerView.ItemDecoration {

    Integer bottomSpaceHeight;

    public final static Integer SHORT_LINE = 1;
    public final static Integer MIDDLE_LINE = 3;
    public final static Integer HIGH_LINE = 6;

    public MyItemDecoration(Integer bottomSpaceHeight) {
        this.bottomSpaceHeight = bottomSpaceHeight;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        if (parent.getChildAdapterPosition(view) != parent.getAdapter().getItemCount()-1){
            outRect.bottom = bottomSpaceHeight;
        }
    }
}